package com.java8.stream;

import com.java8.lambda.bean.Employee;
import org.junit.Test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;

/**
 * 一.Stream的三个操作步骤:
 *
 * 1.创建Stream
 *
 * 2.中间操作
 *
 * 3.终止操作(终端操作)
 */
public class StreamApiTest1 {


    //创建Stream
    @Test
    public void test1() {
        //1.可以通过Collection 系列集合提供的stream()(串行流)或parallelStream()(并行流)
        List<String> list = new ArrayList<>();
        Stream<String> stream = list.stream();


        //2.通过Arrays 中的静态方法stream()获取数组流
        Employee[] employees = new Employee[10];
        Stream<Employee> employeeStream = Arrays.stream(employees);

        //3.通过Stream类中的静态方法of()
        Stream<String> stringStream = Stream.of("aa", "bb", "cc");


        //4.创建无限流
        //迭代
        Stream<Integer> iterate = Stream.iterate(0, (x) -> x + 2);
        iterate.limit(10).forEach(System.out::println);

        //生成
        Stream<Integer> generate = Stream.generate(() -> (int) (Math.random()));
        generate.limit(5).forEach(System.out::println);


    }



}
